<?php
namespace app\bbs\controller;
use x\Xbase;
use x\Container;
class Base extends Xbase{
    public $userinfo = [];
    public $com = [];
    public $sys = [];
    public function __construct(){
        parent::__construct();
        clear_cookie_arr('js');
        $this->_sys();
        $this->_user();
    }

    //通用
    public function _sys(){
        $this->sys = m('Deploy','xcom')->lists();
        $this->assign('sys',$this->sys);
        $this->assign('m',$this->m);
        $this->assign('c',$this->c);
        $this->assign('a',$this->a);
    }

    //验证登陆
    public function _user(){
        $this->userinfo = m('User','c')->isLogin();
        $this->assign('userinfo',$this->userinfo);
    }

    //验证登录
    public function checkLogin(){
        if(!$this->userinfo){
            if(is_ajax()){
                err('请先登录!');
            }else{
                session('need_login_url',com_cur_url());
                jump('请先登录!',url('publics/login'),1,1);
            }
        }
    }

    /**
     * 验证是否是管理员
     * @param  boolean $goback [是否记录来时路由]
     * @return [type]          [description]
     */
    public function isAdmin($goback=false){
        if(!$this->userinfo || $this->userinfo['level']!=4) {
            if(isAjax()){
                err('管理员才有改权限');
            }else{
                $url = $goback?$goback:url('publics/login');
                jump('没有权限',$url,1);
            }
        }
    }
}
